package com.haidechizi.doublecache.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

public class DefaultRemoteCacheService implements RemoteCacheService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void setCache(String cacheKey, Object value, int timeout) {
        redisTemplate.opsForValue().set(cacheKey, value, timeout, TimeUnit.SECONDS);
    }

    @Override
    public Object getCache(String cacheKey) {
        return redisTemplate.opsForValue().get(cacheKey);
    }

    @Override
    public void deleteCache(String cacheKey) {
        redisTemplate.delete(cacheKey);
    }
}
